package com.javaapi.refactor;

import java.util.Enumeration;
import java.util.Vector;

public class Customer {
	private String _name;
	private Vector _rentals = new Vector();

	public Customer(String _name) {
		this._name = _name;
	}

	public String get_name() {
		return _name;
	}

	public void set_name(String _name) {
		this._name = _name;
	}

	public Vector getRentals() {
		return _rentals;
	}

	public void setRentals(Vector rentals) {
		this._rentals = rentals;
	}

	public String statement() {

		double totalAmount = 0; // --总消费金额
		int frequentRenterPoints = 0; // --常客积点
		Enumeration rentals = _rentals.elements();
		String result = "Rental Record for " + get_name() + "/n";

		while (rentals.hasMoreElements()) {
			double thisAmount = 0;
			Rental one = (Rental) rentals.nextElement(); // --取得一笔租借记录

			thisAmount = one.getCharge(thisAmount);

			// ---累加常客积点
			frequentRenterPoints++;
			if (one.get_movie().get_priceCode() == Movie.NEW_RELEASE && one.get_daysRented() > 1)
				frequentRenterPoints++;
			// ---显示此笔租借数据
			result += "/t" + one.get_movie().get_title() + "/t" + String.valueOf(thisAmount) + "/n";
			totalAmount += thisAmount;
		}

		// ---结尾打印
		result += "Amount owed is " + String.valueOf(totalAmount) + "/n";
		result += "You earned " + String.valueOf(frequentRenterPoints) + " frequent renter points";
		return result;
	}

}
